package itsm.isperp.framework.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 
 * 
 * 
 * @author lizx
 * @date 2013-9-12
 * @since 1.0
 * 
 */
public final class DateUtils {

	public static final DateFormat DF_LONG_LONG = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm:ss");

	private static final DateFormat DF_LONG = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm");

	private static final DateFormat DF_SHORT = new SimpleDateFormat(
			"yyyy-MM-dd");

	private static final DateFormat DF_YEAR_MONTH = new SimpleDateFormat(
			"yyyy-MM");

	public static final DateFormat DF_TIME = new SimpleDateFormat("HH:mm");

	public static final SimpleDateFormat DF_SSHORT = new SimpleDateFormat(
			"yyyyMMdd");

	/**
	 * 短类型日期长度
	 */
	public static final int SHORT_DATE = 10;

	public static final DateFormat getDateTimeformat() {
		return new SimpleDateFormat("yyyy-MM-dd HH:mm");
	}

	public static final String formatDateTime(Date date) {
		synchronized (DF_LONG) {
			return DF_LONG.format(date);
		}
	}

	public static final String formatDate(Date date) {

		synchronized (DF_SHORT) {
			return DF_SHORT.format(date);
		}
	}

	public static final String formatYearMonth(Date date) {

		synchronized (DF_YEAR_MONTH) {
			return DF_YEAR_MONTH.format(date);
		}
	}

	public static final Date parseDateTime(String datestr)
			throws ParseException {
		synchronized (DF_LONG) {
			return DF_LONG.parse(datestr);
		}

	}

	public static final Date parseDate(String datestr) throws ParseException {
		synchronized (DF_SHORT) {
			return DF_SHORT.parse(datestr);
		}

	}

}
